import { ModalUtil } from '/@lib/utils/modal.ts'

function clipboardSuccess(text: any) {
  ModalUtil.msgSuccess(`拷贝${text}成功`)
}

function clipboardError(text: any) {
  ModalUtil.msgSuccess(`拷贝${text}失败`)
}

/**
 * @description 复制数据
 * @param text
 */
export default function handleClipboard(text: string) {
  const { isSupported, copy } = useClipboard()
  if (!isSupported) {
    usePermission('clipboard-write')
  }
  copy(text)
    .then(() => {
      clipboardSuccess(text)
    })
    .catch(() => {
      clipboardError(text)
    })
}
